package com.sdcqjy.property.activity;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import com.google.gson.Gson;
import com.sdcqjy.property.R;
import com.sdcqjy.property.base.SimpleBaseActivity;
import com.sdcqjy.property.mode.MessageMode;
import com.sdcqjy.property.presenter.MessageDetailsPresenter;
import com.sdcqjy.property.presenter.contract.MessageDetailsContract;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 磁磁帅 on 2018/5/13.
 * 功能：
 */

public class MessageDetailsActivity extends SimpleBaseActivity<MessageDetailsPresenter> implements MessageDetailsContract.View {
    @BindView(R.id.textTitle)
    TextView textTitle;
    @BindView(R.id.textTime)
    TextView textTime;
    @BindView(R.id.textContent)
    TextView textContent;
    private MessageMode mode;
    private String shijian_;

    public static void open(Context context, MessageMode mode) {
        Intent intent = new Intent(context, MessageDetailsActivity.class);
        intent.putExtra("json", new Gson().toJson(mode));
        context.startActivity(intent);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_details);
        ButterKnife.bind(this);
        presenter = new MessageDetailsPresenter(this);
        Intent intent = getIntent();
        String json = intent.getStringExtra("json");
        if (!TextUtils.isEmpty(json)) {
            mode = new Gson().fromJson(json, MessageMode.class);
        }
    }

    protected void asynRun() {
        if (mode == null) {
            onBackPressed();
            return;
        }
        if (TextUtils.isEmpty(mode.messageContent)) {
            textTitle.setText(mode.messageTitle);
            presenter.getMode(mode.id);
        } else getModeRet(mode);
    }

    public void getModeRet(MessageMode data) {
        mode = data;
        Resources res = getResources();
        shijian_ = res.getString(R.string.shijian_);
        textTime.setText(shijian_ + data.getTime());
        textTitle.setText(data.messageTitle);
        textContent.setText(data.messageContent);
    }
}
